package com.guigu.basedservice.controller;


import com.github.pagehelper.PageInfo;
import com.guigu.basedservice.entity.BaseCarBrand;
import com.guigu.basedservice.entity.BaseCarFactory;
import com.guigu.basedservice.entity.BaseCarType;
import com.guigu.basedservice.service.BaseCarFactoryService;
import com.guigu.basedservice.vo.BaseCarFactoryVo;
import com.guigu.commonutils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 厂家 前端控制器
 * </p>
 *
 * @author Heyuhang
 * @since 2024-09-12
 */
@CrossOrigin
@Api(description = "BaseCarFactory请求控制类")
@RestController
@RequestMapping("/basedservice/base-car-factory")
public class BaseCarFactoryController {

    @Autowired
    private BaseCarFactoryService baseCarFactoryService;

    @ApiOperation("查询所有BaseCarFactory分页数据")
    @RequestMapping("/show/{currentPage}/{pageSize}")
    public R show(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @RequestBody BaseCarFactoryVo vo
    ){
        PageInfo<BaseCarFactory> baseCarFactoryPageInfo = baseCarFactoryService.show(vo,currentPage, pageSize);
        System.out.println("baseCarFactoryPageInfo++++"+baseCarFactoryPageInfo);
        return R.ok().data("baseCarFactoryPageInfo", baseCarFactoryPageInfo);
    }

    @ApiOperation("查询所有BaseCarFactory数据")
    @RequestMapping("/list")
    public R list() {
        List<BaseCarFactory> baseCarFactoryList = baseCarFactoryService.list(null);
        return R.ok().data("baseCarFactoryList", baseCarFactoryList);
    }

    @ApiOperation("添加BaseCarFactory数据")
    @PostMapping("/add")
    public R add(@RequestBody BaseCarFactory baseCarFactory){
        baseCarFactory.setNamePy("heyuhang");
        baseCarFactory.setVersion(BigDecimal.valueOf(0));
        baseCarFactoryService.save(baseCarFactory);
        return R.ok().message("成功");
    }

    @RequestMapping("/getOne/{id}")
    public BaseCarFactory getOne(@PathVariable("id") String id){
        return baseCarFactoryService.getById(id);
    }

    @ApiOperation("修改BaseCarFactory分页数据")
    @RequestMapping("/update")
    public Boolean update(@RequestBody BaseCarFactory baseCarFactory){
        return baseCarFactoryService.updateById(baseCarFactory);
    }

    @RequestMapping("/delete/{factoryUuid}")
    public Boolean delete(@PathVariable String factoryUuid){
        return baseCarFactoryService.removeById(factoryUuid);
    }


}

